<template>
  <div class="counter-component counter-c">
    <h3>计数器 C</h3>
    <p>当前计数: {{ count }}</p>
    <button @click="increment">增加</button>
    <button @click="decrement">减少</button>
    <button @click="double">双倍</button>
    <button @click="reset">重置</button>
    <p class="timestamp">创建时间: {{ timestamp }}</p>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const count = ref(0)
const timestamp = ref(new Date().toLocaleTimeString())

const increment = () => {
  count.value++
}

const decrement = () => {
  count.value--
}

const double = () => {
  count.value *= 2
}

const reset = () => {
  count.value = 0
}

onMounted(() => {
  console.log('CounterC 已挂载')
})

onUnmounted(() => {
  console.log('CounterC 已卸载')
})
</script>

<style scoped>
.counter-c {
  background-color: #e8f5e8;
  padding: 20px;
  border-radius: 8px;
  border: 2px solid #4caf50;
}

.counter-c h3 {
  color: #388e3c;
  margin-bottom: 15px;
}

.counter-c button {
  margin: 0 10px 10px 0;
  padding: 8px 16px;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.counter-c button:hover {
  background-color: #388e3c;
}

.timestamp {
  font-size: 12px;
  color: #666;
  margin-top: 10px;
}
</style>
